package SpaceIT.pages;

import java.util.ArrayList;

import model.dao.DongSanPhamDAO;
import model.dao.NhaSanXuatDAO;
import model.dao.SanPhamDAO;
import model.pojo.DongSanPham;
import model.pojo.HangSanXuat;

import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.Request;

import view.util.util;
import controller.util.ControllerHelper;

public class SanPham 
{
	@Property
	private util viewHelper ;
	
	@Inject
	private Request request;
	
	@Property
	private int i;
	
	@Property
	private int j;
	
	@Property
	private int Option;
	
	@Property
	private ArrayList<ArrayList<String>> arr;//san pham
	
	@Property
	private ArrayList<String> arr1;//khung chua san pham,moi khung 6 sp
	
	public SanPham(){
//	{
		viewHelper = new util();
	}
	
	public void onActivate(){
//	{
		String s = request.getParameter("op");
		if(s != null )
		{
			if(s.equals("1"))
				Option = 1 ;
			else			
				Option = 0 ;
		}
	}
	
	public int SoLuongKhungSanPhamMoi(){
//  {
		String url = "ChiTietLaptop?MaSP=";
		if(Option != 1)
			url = "ChiTietSanPham?MaSP=";
		arr1 = ControllerHelper.PhanTrang(url , SanPhamDAO.LaySanPhamMoi(Option)) ;
		if(arr1 == null)
			return 0;
		return arr1.size();
    }
	
	public int SoLuongKhungSanPhamNoiBat(){
//  {
		String url = "ChiTietLaptop?MaSP=";
		if(Option != 1)
			url = "ChiTietSanPham?MaSP=";
		arr1 = ControllerHelper.PhanTrang(url , SanPhamDAO.LaySanPhamNoiBat(Option)) ;
		if(arr1 == null)
			return 0;
		return arr1.size();
    }
	
	public int SoLuongKhungTop10SanPham(){
//  {
		String url = "ChiTietLaptop?MaSP=";
		if(Option != 1)
			url = "ChiTietSanPham?MaSP=";
		arr1 = ControllerHelper.PhanTrang(url , SanPhamDAO.Top10SanPhamBanNhieu(Option)) ;
		if(arr1 == null)
			return 0;
		return arr1.size();
    }
	
	public boolean isLaptop(){
//	{
		if(Option == 1)
			return true;
		return false;
	}
	
	public boolean isOutPut(){
//	{
		if (i < arr1.size())
			return true;
		return false;
	}
}
